
package com.joysuch.wwyt.core.controller;

import cn.hutool.core.util.StrUtil;
import com.joysuch.wwyt.config.RedisClient;
import com.joysuch.wwyt.core.bean.UserInfoBean;
import com.joysuch.wwyt.core.bean.UsernamePasswordTokenWithCompanyCode;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.constant.Constants;
import com.joysuch.wwyt.core.entity.BaseConfig;
import com.joysuch.wwyt.core.entity.BaseLoginAccount;
import com.joysuch.wwyt.core.entity.BaseUser;
import com.joysuch.wwyt.core.repository.BaseLoginAccountDao;
import com.joysuch.wwyt.core.repository.BaseUserDao;
import com.joysuch.wwyt.core.security.ShiroUser;
import com.joysuch.wwyt.core.service.BaseConfigService;
import com.joysuch.wwyt.core.service.BaseLoginService;
import com.joysuch.wwyt.core.service.BaseUserService;
import com.joysuch.wwyt.core.support.Context;
import com.joysuch.wwyt.licence.bean.LicenceCacheDto;
import com.joysuch.wwyt.licence.constant.LicenceStateEnum;
import com.joysuch.wwyt.licence.service.LicenceService;
import com.joysuch.wwyt.util.AESUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Controller
@RequestMapping("/")
@Slf4j
@Api(tags = "/ 登录相关")
public class LoginController {

    private static final Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private BaseLoginService baseLoginService;

    @RequestMapping("login")
    public String login(HttpServletRequest request) {
        return "login";
    }

    @RequestMapping("doLogin")
    @ApiOperation("登录")
    public ModelAndView doLogin(String name, String key, HttpServletRequest request) {
        return baseLoginService.doLogin(name, key, request);
    }

    @PostMapping("doLoginApp")
    @ApiOperation("登录")
    public ModelAndView doLoginApp(String name, String key, HttpServletRequest request) {
        return baseLoginService.doLogin(name, key, request);
    }

    //免密登录
    @GetMapping("login/loginBycode")
    @ApiOperation("第三方跳转登录")
    public ModelAndView doLoginByUserCode(String code, HttpServletRequest request) {
        return baseLoginService.doLoginByUserCode(code, request);
    }

    @RequestMapping("logout")
    @ResponseBody
    public Object logout(HttpServletRequest request) {
        return baseLoginService.logout(request);
    }


}
